<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>用户创单</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="assets/img/logo.png">
    <link rel="stylesheet" href="assets/css/amazeui.min.css" />
    <link rel="stylesheet" href="assets/css/amazeui.datatables.min.css" />
    <link rel="stylesheet" href="assets/css/app.css">
    <script src="assets/js/jquery.min.js"></script>
</head>
<body data-type="widgets">
<script src="assets/js/theme.js"></script>
<div class="am-g tpl-g">
    <!-- 头部 -->
    <header>
        <!-- logo -->
        <div class="am-fl tpl-header-logo">
            <a href="javascript:;">
                <img src="assets/img/logo.png" style="width:30px;">
            </a>
        </div>
        <!-- 右侧内容 -->
        <div class="tpl-header-fluid">
            <!-- 侧边切换 -->
            <div class="am-fl tpl-header-switch-button am-icon-list"></div>
            <!-- 其它功能-->
            <div class="am-fr tpl-header-navbar">
                <ul>
                    <!-- 欢迎语 -->
                    <li class="am-text-sm tpl-header-navbar-welcome">
                        <a href="javascript:;">欢迎你，<span>管理员</span> </a>
                    </li>
                    <!-- 新提示 -->
                    <li class="am-dropdown" data-am-dropdown id="orderNewList"></li>
                    <!-- 退出 -->
                    <li class="am-text-sm">
                        <a href="javascript:;">
                            <span class="am-icon-sign-out"></span> 退出
                        </a>
                    </li>
                </ul>
            </div>
        </div>
    </header>
    <!-- 头部 -->
    <!-- 风格切换 -->
    <div class="tpl-skiner"></div>
    <!-- 风格切换 -->
    <!-- 侧边导航栏 -->
    <div class="left-sidebar">
        <!-- 用户信息 -->
        <div class="tpl-sidebar-user-panel"></div>
        <!-- 菜单 -->
        <ul class="sidebar-nav"></ul>
    </div>
    <!-- 侧边导航栏 -->

    <!-- 内容区域 -->
    <div class="tpl-content-wrapper">
        <div class="row-content am-cf">
            <div class="row">
                <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                    <div class="widget am-cf">
                        <div class="widget-head am-cf">
                            <div class="widget-title  am-cf">库视频：用户创作</div>
                        </div>
                        <div class="widget-body  am-fr">
                            <!--菜单-->
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                <div class="am-form-group tpl-table-list-select">
                                    <select data-am-selected="{btnSize: 'sm'}" id="vid"
                                            onchange="$('#selvid')[0].value=this.value;">
                                        <option value="0">选择视频</option>
                                    </select>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                <div class="am-form-group tpl-table-list-select">
                                    <select data-am-selected="{btnSize: 'sm'}" id="uid"
                                            onchange="$('#seluid')[0].value=this.value;">
                                        <option value="0">选择用户</option>
                                    </select>
                                </div>
                            </div>
                            <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                    <span class="am-input-group-btn">
                                        <button class="am-btn  am-btn-default am-btn-success
                                            tpl-table-list-field am-icon-search" type="button"
                                                onclick="getIndex()"></button>
                                    </span>
                                </div>
                            </div>
                            <!--数据列表-->
                            <div class="am-u-sm-12">
                                <table width="100%" class="am-table am-table-compact
                                    am-table-striped tpl-table-black ">
                                    <thead>
                                    <tr>
                                        <th>视频封面</th>
                                        <th>视频标题</th>
                                        <th>用户</th>
                                        <th>是否删除</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    </tbody>
                                </table>
                            </div>
                            <!--分页-->
                            <div class="am-u-lg-12 am-cf">
                                <div class="am-fr">
                                    <ul class="am-pagination tpl-pagination">
                                        <li>共计0条，共0页 &nbsp; &nbsp; </li>
                                        <li class="am-disabled"><a href="#">首页</a></li>
                                        <li class="am-active"><a href="#">上一页</a></li>
                                        <li><a href="#">下一页</a></li>
                                        <li><a href="#">尾页</a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- 内容区域 -->
</div>

<!--自定义弹窗-->
<div id="selfPop"></div>

<!--分页处理-->
<input type="hidden" id="pageTail" value="0">
<!--搜索处理-->
<input type="hidden" id="selvid" value="0">
<input type="hidden" id="seluid" value="0">
</body>
</html>


<script src="assets/js/amazeui.min.js"></script>
<script src="assets/js/app.js"></script>
<script src="assets/js/myself.js"></script>
<script type="text/javascript">
    var domain = getDomain();
    var page = getUrlParam('page');
    var view = getUrlParam('view');
    var pageSize = 2; //一页显示记录
    (function(){
        getLeftMenus();
        getLoginUser();
        getNewOrder();
        getConditions();
        getIndex();
    })();
    //获取视频\用户
    function getConditions(){
        var formData = {
            adminAccess:adminAccess
        };
        $.ajax({
            type:'POST',
            url:domain+'/stock/plus/condidtion',
            data:formData,
            success:function(res){
                console.log(res);
                var si, slist = ''; //库视频
                var ui, ulist = ''; //用户
                slist += '<option value="0">选择标题</option>';
                ulist += '<option value="0">选择用户</option>';
                if (res.code!=0) {
                    $("#vd").html(slist);
                    $("#uid").html(ulist);
                    return
                }
                var stocks = res.data.stocks;
                var users = res.data.users;
                for (si=0;si<stocks.length;si++) {
                    slist += '<option value="'+stocks[si].videoId+'">';
                    slist += stocks[si].videoTitle;
                    slist += '</option>';
                }
                for (ui=0;ui<users.length;ui++) {
                    ulist += '<option value="'+users[ui].uid+'">';
                    ulist += users[ui].uname;
                    ulist += '</option>';
                }
                $("#vid").html(slist);
                $("#uid").html(ulist);
            },
            error:function(xhr,type,errorThrown){
//                console.log('网络错误');
                getSelfPop('网络错误');
            }
        });
    }
    //获取数据列表
    function getIndex(){
        var vid = $("#selvid").val();
        var uid = $("#seluid").val();
        var formData = {
            adminAccess:adminAccess,
            page:page,
            size:pageSize,
            vid:vid,
            uid:uid
        };
        $.ajax({
            type:'POST',
            url:domain+'/stock/plus/index',
            data:formData,
            success:function(res){
                console.log(res);
                if (res.code!=0) {
//                    console.log(res.msg); return
                    getSelfPop(res.msg); return
                }
                getSelfPop('获取成功');
                //显示数据
                var list = res.data;
                var total = res.total;
                $("#pageTail")[0].value = total;
                var i, title, uname, h = '';
                for (i=0;i<list.length;i++) {
                    title = getStrLimitNum(list[i].videoTitle,15);
                    uname = getStrLimitNum(list[i].uname,15);
                    h += '<tr class="gradeX">';
                    h += '<td>';
                    if (list[i].videoImg) {
                        h += '<a href="'+list[i].videoLink+'" target="_bank">';
                        h += '<img src="'+list[i].videoImg+'" class="tpl-table-line-img">';
                        h += '</a>';
                    } else {
                        h += '/';
                    }
                    h += '</td>';
                    h += '<td class="am-text-middle">';
                    h += title;
                    h += '</td>';
                    h += '<td class="am-text-middle">'+uname+'</td>';
                    h += '<td class="am-text-middle">';
                    h += list[i].del==0 ? '<span style="color:#00FFFF;">未删除</span>' :
                            '<span style="color:#FF00FF;">已删除</span>';
                    h += '</td>';
                    h += '<td class="am-text-middle">';
                    h += '<div class="tpl-table-black-operation">';
//                    //编辑
//                    h += '<a href="/admin/stockForm.html?view=1&vid='+list[i].videoId+'"> <i class="am-icon-pencil"></i> 编辑 </a>';
//                    h += ' &nbsp; ';
                    //看视频
                    if (list[i].videoType==2) {
                        h += '<a href="'+list[i].videoLink+'" target="_bank"> ';
                    } else {
                        h += '<a href="/admin/play.html?vtitle='+list[i].videoTitle+'&vlink='+list[i].videoLink+'" target="_bank"> ';
                    }
                    h += '<i class="am-icon-archive"></i> 看视频 ';
                    h += '</a>';
                    h += ' &nbsp; ';
                    if (list[i].del==0) {
                        h += '<a href="javascript:;" onclick="setDel('+list[i].videoId+')" class="tpl-table-black-operation-del"> <i class="am-icon-trash"></i> 删除 </a>';
                    } else {
                        h += '<a href="javascript:;" onclick="setRedo('+list[i].videoId+')" class="tpl-table-black-operation-del"> <i class="am-icon-trash"></i> 还原 </a>';
                    }
                    h += '</div>';
                    h += '</td>';
                    h += '</tr>';
                }
                $("tbody").html(h);
                //分页处理
                setPage(total);
            },
            error:function(xhr,type,errorThrown){
//                console.log('网络错误');
                getSelfPop('网络错误');
            }
        });
    }
    //分页处理
    function setPage(total){
        var pageTotal = Math.ceil(total / pageSize) - 1; //页面总数
        var pageHome, pageTail, pagePre, pageNext; //首页，尾页，上一页，下一页
        pageHome = 0; //首页
        if (page > 0) { //上一页
            pagePre = page * 1 - 1;
        } else {
            pagePre = page;
        }
        if (page < pageTotal) { //下一页
            pageNext = page * 1 + 1;
        } else {
            pageNext = page;
        }
        pageTail = pageTotal; //尾页
        pageCurr = page * 1 + 1; //当前页面
        var h = '';
        h += '<li>';
        h += '共计'+total+'条，';
        h += '共'+pageTotal+'页， ';
        h += '当前第'+pageCurr+'页， ';
        h += '&nbsp; &nbsp; </li>';
        if (page==0) {
            h += '<li class="am-abled">';
        } else {
            h += '<li class="am-active">';
        }
        h += '<a href="javascript:;" onclick="setVideoPage('+pageHome+')">首页</a>';
        h += '</li>';
        if (page==0) {
            h += '<li class="am-abled">';
        } else {
            h += '<li class="am-active">';
        }
        h += '<a href="javascript:;" onclick="setVideoPage('+pagePre+')">上一页</a>';
        h += '</li>';
        if (page==pageTail) {
            h += '<li class="am-abled">';
        } else {
            h += '<li class="am-active">';
        }
        h += '<a href="javascript:;" onclick="setVideoPage('+pageNext+')">下一页</a>';
        h += '</li>';
        if (page==pageTail) {
            h += '<li class="am-abled">';
        } else {
            h += '<li class="am-active">';
        }
        h += '<a href="javascript:;" onclick="setVideoPage('+pageTail+')">尾页</a>';
        h += '</li>';
        $("#pageLi").html(h);
    }
    //获取分页数据
    function setVideoPage(next){
        var pageTail = $("#pageTail").val();
        if (next==Number(page) && Number(page)==0) {
            getSelfPop('已在首页'); return
        }
        else if (next==Number(page) && Number(page)==Number(pageTail)) {
            getSelfPop('已在尾页'); return
        }
        else if (next==Number(page)) {
            getSelfPop('已在当前页面'); return
        }
        window.location.href = domain+'/stock.html?view='+view+'&page='+next;
    }
    //设置删除
    function setDel(vid){
        var formData = {
            adminAccess:adminAccess,
            vid:vid
        };
        $.ajax({
            type:'POST',
            url:domain+'/stock/del',
            data:formData,
            success:function(res){
                console.log(res);
                if (res.code!=0) {
//                    console.log(res.msg); return
                    getSelfPop(res.msg); return
                }
                getSelfPop('删除成功');
                setTimeout(function(){
                    window.location.href = '';
                }, 1000);
            },
            error:function(xhr,type,errorThrown){
                console.log('网络错误');
            }
        });
    }
    //设置还原
    function setRedo(vid){
        var formData = {
            adminAccess:adminAccess,
            vid:vid
        };
        $.ajax({
            type:'POST',
            url:domain+'/stock/redo',
            data:formData,
            success:function(res){
                console.log(res);
                if (res.code!=0) {
//                    console.log(res.msg); return
                    getSelfPop(res.msg); return
                }
                getSelfPop('删除成功');
                setTimeout(function(){
                    window.location.href = '';
                }, 1000);
            },
            error:function(xhr,type,errorThrown){
                console.log('网络错误');
            }
        });
    }
</script>